﻿using System;
using System.Xml;
using digiTwitter.ExtensionMethods;

namespace digiTwitter
{
    /// <summary>
    /// Represents a user in Twitter site
    /// </summary>
    public class TwitterUser
    {
        public int      Id { get; set; }
        public String   UserName { get; set; }
        public String   ScreenName { get; set; }
        public int      Followers { get; set; }
        public String   Name { get; set; }
        public String   Location { get; set; }
        public String   Description { get; set; }
        public String   ProfileImageURL { get; set; }
        public String   URL { get; set; }
        public bool     Protected { get; set; }
        public String   ProfileBackgroundColor { get; set; }
        public String   ProfileTextColor { get; set; }
        public String   ProfileLinkColor { get; set; }
        public String   ProfileSideBarFillColor { get; set; }
        public String   ProfileSideBarBorderColor { get; set; }
        public String   ProfileBackgroundImageURL { get; set; }
        public int      FriendsCount { get; set; }
        public int      FavouritesCount { get; set; }        
        public DateTime CreatedAt { get; set; }
        public String   TimeZone { get; set; }
        public int      UTCOffset { get; set; }
        public bool     Following { get; set; }
        public bool     Notifications { get; set; }
        public String   ProfileBackgroundTitle { get; set; }
        public int      StatusesCount { get; set; }
        public TwitterStatus Status  { get; set; }

        /// <summary>
        /// Default constructor.
        /// </summary>
        public TwitterUser(){}
       
        /// <summary>
        /// Overload constructor based on a XmlDocument.
        /// </summary>
        /// <param name="doc"></param>
        public TwitterUser(XmlDocument doc)
        {
            XmlNode userNode = doc.SelectSingleNode("user");
            if (userNode != null)
            {
                Id = userNode.GetInt("id");
                UserName = userNode.GetString("username"); ;
                ScreenName = userNode.GetString("screen_name"); ;
                ProfileImageURL = userNode.GetString("profile_image_url");
                ProfileBackgroundColor = userNode.GetString("profile_background_color");
                ProfileTextColor = userNode.GetString("profile_text_color");
                ProfileLinkColor = userNode.GetString("profile_link_color");
                ProfileSideBarFillColor = userNode.GetString("profile_sidebar_fill_color");
                ProfileSideBarBorderColor = userNode.GetString("profile_sidebar_border_color");
                ProfileBackgroundImageURL = userNode.GetString("profile_background_image_url");
                ProfileBackgroundTitle = userNode.GetString("profile_background_title");
                CreatedAt = userNode.GetDateTime("created_at");
                FavouritesCount = userNode.GetInt("favourites_count"); 
                Followers = userNode.GetInt("followers_count");
                FriendsCount = userNode.GetInt("friends_count");
                Following = userNode.GetBool("following");
                Notifications = userNode.GetBool("notifications");
                Name = userNode.GetString("name");
                Location = userNode.GetString("location");
                URL = userNode.GetString("url");
                TimeZone = userNode.GetString("time_zone");
                UTCOffset = userNode.GetInt("utc_offset");
                StatusesCount = userNode.GetInt("statuses_count");
                Description = userNode.GetString("description");
                Protected = userNode.GetBool("protected");

                if(userNode.SelectSingleNode("status")!= null)
                    Status = new TwitterStatus(userNode.SelectSingleNode("status"));
            }
        }
    }
}
